use "../Intermediate/analysis_panel_firmyear", clear

bys borrower_id: egen total_treat = total(ss_pre_all_debt_banintsty_n1_sd)
egen med_treat = median(total_treat)
gen high_total_treat = total_treat > med_treat

collapse (sum) borr_loan, by(high_total_treat year)

tsset high_total_treat year
replace borr_loan    = borr_loan/1e3
tssmooth ma borr_loan_ma = borr_loan, window(2 1)

gen borr_loan_ma_2010 = borr_loan_ma if year == 2010
bys high_total_treat (borr_loan_ma_2010): replace borr_loan_ma_2010 = borr_loan_ma_2010[1]

gen borr_loan_ma_s10 = borr_loan_ma / borr_loan_ma_2010
label var borr_loan_ma_s10 "Scaled Aggregate Coal Lending"

sort high_total_treat year
save "../Intermediate/Figure_6", replace
